//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.vere.rpc.server;

import com.vere.rpc.model.ServiceItem;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ConcurrentHashMap;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

public class RegistryService {
    private static ConcurrentHashMap<String, ServiceItem> mapService = new ConcurrentHashMap();
    private static String classAbsolutePath = "";
    private static String configFileName = "VereRPC.xml";

    static {
        Object obj = new Object();
        if (classAbsolutePath == null || "".equals(classAbsolutePath)) {
            URL url = obj.getClass().getResource("/");
            if (url == null) {
                url = Thread.currentThread().getContextClassLoader().getResource("");
            }

            classAbsolutePath = url.getPath();
            loadResources();
        }

    }

    public RegistryService() {
    }

    public static ServiceItem getService(String serviceName) {
        return (ServiceItem)mapService.get(serviceName);
    }

    public static void loadResources() {
        String currentClassPath = classAbsolutePath;
        if (currentClassPath != null && !"".equals(currentClassPath)) {
            FileInputStream is = null;

            try {
                SAXReader reader = new SAXReader();
                String filePath = classAbsolutePath + configFileName;
                is = new FileInputStream(filePath);
                if (is == null) {
                    return;
                }

                Document doc = reader.read(is);
                List<Element> elementList = doc.selectNodes("/VereRPC/service");
                Iterator var7 = elementList.iterator();

                while(var7.hasNext()) {
                    Element element = (Element)var7.next();
                    String serviceInterface = element.attributeValue("interface");
                    String serviceClass = element.attributeValue("class");
                    mapService.put(serviceInterface, new ServiceItem(serviceInterface, serviceClass));
                }
            } catch (Exception var19) {
                var19.printStackTrace();
            } finally {
                try {
                    is.close();
                } catch (IOException var18) {
                    var18.printStackTrace();
                }

            }

        }
    }
}
